import { util } from "../../common/util";
import { config } from "../../config";

const saleInfo = util.getLocalStorage('saleInfo_' + config.appName) || {};

const state = {//数据
  saleInfo: saleInfo, // 用户信息 头像 昵称
}

const getters = {//获取数据
  getSaleInfo: state => state.saleInfo,
}

const mutations = {//对本地无需ajax的更改，使用mutations
  updateSaleInfo (state, changed) {
    state.saleInfo = changed;
    util.setLocalStorage('saleInfo_' + config.appName, changed);
  },
  clearSaleInfo (state, changed) {
    state.saleInfo = {};
    util.delLocalStorage('saleInfo_' + config.appName);
  }
}

const actions = {//action好处适合异步操作，action先执与后端交互，mutations后执行
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
